import java.util.Scanner;

public class R2 {
     //2.猜数字游戏使用随机的方式生成一个“谜底”，让用户循环的录入，
	//提示大了，或者小了，直到猜出来为止，游戏结束后，输出猜数字的次数
	//int num = (int)(Math.random()*100);System.out.println(num);
	/*public static void main(String[] args) {
		double num1=Math.random();
		int a=(int)(num1*100);
	//	System.out.println(a);
		Scanner sc = new Scanner(System.in);
		
		int i=0;
		int num=50;
		while (i<= num) {
			i++;
			System.out.println("请输入数字");
			int num2=sc.nextInt();
			if (num2>a) {
				System.out.println("大了");
				continue;
			}else if(num2<a){
				System.out.println("小了");
				continue;
			}else {
				System.out.println("游戏结束");
				break;
			}
		}
		System.out.println("猜数字的次数:"+i);
	}*/
	
	public static void main(String[] args) {
        getD();
	}
	
	public static int getD() {
	int num=(int)(Math.random()*100);
	//System.out.println(num);
	Scanner scanner=new Scanner(System.in);
	int num1=0;
	int t=0;
	while (true) {
		System.out.println("猜数字");
		num1=scanner.nextInt();
		t++;
		if (num1>num) {
			System.out.println("大了");
		}else if (num1<num) {
			System.out.println("小了");
		}else {
			System.out.println("中了");
			break;
		}
	}
	System.out.println("猜数字的次数:"+t);
	return t;
	}
}
